package be.bonamis.timesheet.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import be.bonamis.timesheet.dto.PrestationTypeDTO;
import be.bonamis.timesheet.model.PrestationType;
import be.bonamis.timesheet.repository.PrestationTypeRepository;
import be.bonamis.timesheet.service.PrestationTypeService;

/**
 * This implementation of the ProjectService interface communicates with the
 * database by using a Spring Data JPA repository.
 * 
 * @author Florent Bonamis
 */
@Service
public class RepositoryPrestationTypeService implements PrestationTypeService{


	@Resource
	private PrestationTypeRepository prestationTypeRepository;

	private static final Logger LOGGER = LoggerFactory
			.getLogger(RepositoryProjectService.class);

	@Transactional
	@Override
	public PrestationType create(PrestationTypeDTO created) {
		LOGGER.debug("Creating a new PrestationType with information: " + created);

		
		PrestationType type = PrestationType.getBuilder(created.getDescription(), created.getDefaultTime()).build();

		return prestationTypeRepository.save(type);
	}

//	@Transactional(rollbackFor = ProjectNotFoundException.class)
	@Override
	public PrestationType delete(Long projectId) {
//		LOGGER.debug("Deleting project with id: " + projectId);
//
//		Project deleted = projectRepository.findOne(projectId);
//
//		if (deleted == null) {
//			LOGGER.debug("No project found with id: " + projectId);
//			throw new ProjectNotFoundException();
//		}
//
//		projectRepository.delete(deleted);
//		return deleted;
		return null;
	}

	@Transactional(readOnly = true)
	@Override
	public List<PrestationType> findAll() {
		LOGGER.debug("Finding all prestationTypes ");
		return prestationTypeRepository.findAll();
	}

	@Transactional(readOnly = true)
	@Override
	public PrestationType findById(Long id) {
		LOGGER.debug("Finding project by id: " + id);
		return prestationTypeRepository.findOne(id);
	}

	//@Transactional(rollbackFor = PersonNotFoundException.class)
	@Override
	public PrestationType update(PrestationType updated)  {
//		LOGGER.debug("Updating person with information: " + updated);
//
//		Project project = projectRepository.findOne(updated.getId());
//
//		if (project == null) {
//			LOGGER.debug("No person found with id: " + updated.getId());
//			throw new ProjectNotFoundException();
//		}
//
//		project.update(updated.getName());
//
//		return project;
		return null;
	}

}
